import os
import sys
import time

from selenium import webdriver
from selenium.webdriver.common.by import By
import pytest
from selenium.webdriver.support.wait import WebDriverWait  # 等待模块
from selenium.webdriver.support import expected_conditions as ec
from ..Data.Data import Data

class Loan_Operation:
    def driver(self):
        driver = webdriver.Chrome()
        driver.get("http://localhost:90/")
        driver.maximize_window()
        return driver


    def login(self, username, password, driver):
        driver.implicitly_wait(5)
        ele1 = (driver.find_element(By.XPATH, "//*[@id='username']"))
        ele1.send_keys(username)
        ele2 = (driver.find_element(By.XPATH, '//*[@id="password"]'))
        ele2 .send_keys(password)
        ele3 = (driver.find_element(By.XPATH, '// *[ @ id = "login_btn"]'))
        ele3.click()
        time.sleep(1)
        return driver


    def loan(self,loanmoney,date,driver):
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/a').click()
        driver.find_element(By.XPATH, '//*[@href="/user/tools/toApplyLoan.html"]').click()
        driver.find_element(By.XPATH, "//*[@id='amount']").send_keys(loanmoney)
        driver.find_element(By.XPATH, "//*[@id='term']").send_keys(date)
        time.sleep(1)
        driver.find_element(By.XPATH, "//*[@id='submit']").click()
        time.sleep(1)
        driver.find_element(By.XPATH, "//button[text()='确认']").click()
        time.sleep(2)

    def GetSuccessResult(self,sql):
        result=Data().select(sql)
        return result

    def assertResult(self,result,expect):
        if result == expect:
            print("通过！")
        else:
            print("不通过！")
        assert result==expect
